package cn.crystalling.app.attendance;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;

import java.io.File;

@SuppressWarnings("all")
public class WelcomeActivity extends AppCompatActivity {
    private Handler handler ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_welcome);

        SharedPreferences shared = getSharedPreferences("Attendance_SP", MODE_PRIVATE);
        SharedPreferences.Editor editor = shared.edit();
        boolean isCreatedDir = shared.getBoolean("isCreatedDir",false);
        if(!isCreatedDir) {
            // 目录为 /storage/emulated/0/Android/data/cn.crystalling.app.attendance/files/
            File filesDir = getExternalFilesDir("");
            if (filesDir.exists()){
                editor.putBoolean("isCreatedDir", true);
            }else {
                editor.putBoolean("isCreatedDir", false);
            }
            editor.apply();
        }

        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == 1) {
                    Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
                    startActivity(intent);
                    WelcomeActivity.this.finish();
                }
            }

        };

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                handler.sendEmptyMessage(1);
            }
        }).start();
    }
}
